<?php
namespace app\service;

use app\model\MemberThirdOauthModel;
use EasyWeChat\Factory;
use support\facade\Logger;
use const support\CORRECT;

class MiniProgramService{

    //获取登录标识
    public static function getMemberOpenid(string $jsCode){
        try {
            $config=config('wechat.mini_program');
            //获取用户标识信息
            $user = Factory::miniProgram($config)->auth->session($jsCode);
            Logger::app('获取用户小程序标识信息','info',$user);
            return $user['openid']??'';
        }catch (\Throwable $e){
            Logger::app($e);
            return false;
        }
    }

    //检测头像昵称是否存在
    public static function checkNicknameAndAvatarPerfect(int $thirdOauthId): bool
    {
        $info=MemberThirdOauthModel::where([
            'id'=>$thirdOauthId,
            'status'=>CORRECT
        ])->select('id','third_nickname','third_avatar')->first()->toArray();
        if ($info['third_nickname'] && $info['third_avatar']){
            return true;
        }
        return false;
    }

}